{layout name="layout"}
<link href="__CSS__/admin.css" rel="stylesheet">
<div class="panel">
    <div class="panel-body">
        <div class="pad-btm form-inline">
            <div class="row">
                <div class="col-sm-6 table-toolbar-left">
                    <button id="node-btn-addrow" data-target="#nodes-modal" data-toggle="modal" class="btn btn-default"><i class="fa fa-plus-circle"></i> 添加</button>
                </div>
            </div>
        </div>
        <div class="table-responsive">
            <table class="table table-striped">
                <thead>
                    <tr>
                        <th>节点名</th>
                        <th>路径</th>
                        <th>图标</th>
                        <th>是否启用</th>
                        <th>排序</th>
                        <th>更新时间</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    {if $nodelist}
                        {foreach $nodelist as $node}
                        <tr>
                            <td>{$node.name}</td>
                            <td class="text-center">{$node.link}</td>
                            <td class="text-center" style="font-size: 16px;"><i class="{$node.icon}"></i></td>
                            <td class="text-center">{$node.is_use}</td>
                            <td class="text-center">{$node.order}</td>
                            <td class="text-center">{$node.last_modify}</td>
                            <td class="text-center">
                                <div class="btn-group">
                                    <button class="btn btn-default" data-target="#nodes-modal" data-toggle="modal" data-nodeid="{$node.node_id}"><i class="fa fa-pencil-square-o"></i></button>
                                    <button class="btn btn-default" onclick='del_node(this,"{$node.node_id}")'><i class="ion-trash-b"></i></button>
                                </div>
                            </td>
                        </tr>
                        {/foreach}
                    {/if}
                </tbody>
            </table>
        </div>
    </div>
</div>
{include file="modals/nodes-modal"}
<script type="text/javascript">
    function del_node(e,nodeid){
        $.ajax({
            url:"{:url('admin/nodes/del_node')}",
            type:"post",
            data:{"nodeid":nodeid},
            dataType:"json",
            success:function(result){
                if(result.status == 'success'){
                    $.niftyNoty({
                        type: 'success',
                        icon : 'pli-exclamation icon-2x',
                        message : result.msg,
                        container : 'floating',
                        timer : 1500,
                    });
                    $(e).parents('tr').detach();
                }else{
                    $.niftyNoty({
                        type: 'warning',
                        icon : 'pli-exclamation icon-2x',
                        message : result.msg,
                        container : 'floating',
                        timer : 1500,
                    });
                }
            },
            error:function(){
                $.niftyNoty({
                    type: 'danger',
                    icon : 'pli-exclamation icon-2x',
                    message : '网络连接失败',
                    container : 'floating',
                    timer : 1500,
                });
            }
        });
    }
</script>